package com.apestech.framework.sql.condition;

import com.apestech.api.query.sys.SysSql;
import com.apestech.framework.db.Format;
import com.apestech.framework.db.callback.FieldValueCallback;
import com.apestech.framework.dictionary.modul.Table;
import com.apestech.framework.json.JSON;
import com.apestech.framework.json.JSONArray;
import com.apestech.framework.json.JSONObject;
import com.apestech.framework.sql.callback.OSqlCallback;
import com.apestech.framework.sql.callback.SqlCallback;
import com.apestech.framework.sql.modul.FieldCondition;
import com.apestech.framework.sql.modul.FromList;
import com.apestech.framework.util.StringUtil;
import com.apestech.framework.xml.plugin.modul.GridHead;
import com.apestech.framework.xml.plugin.modul.QryConfig;
import com.apestech.framework.xml.sql.modul.QueryRule;
import com.apestech.framework.xml.sql.modul.QueryhTw;
import com.apestech.framework.xml.sql.SqlNodeVar;
import com.apestech.framework.xml.sql.modul.SqlRule;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Map;

/**
 * @author hup
 * @create 2018-08-16-11:55
 */
public class ConditionMap extends StringUtil{

    public class SysParam{
        private boolean xls=false;     //xls查询模式
        private boolean bmath=false;
        private boolean alldata=false;
        private boolean othercon=false;
        private boolean printSql=true;
        private boolean noSum=false;
        private String postId;
        //查询方式
        private String xmlSql;
        private String sql;
        private String orderSql;
        private String sqlType;
        private String dbType;
        private String nodeName;
        private String nodeid;
        private String pageType="query";
        //特殊处理
        private String timeField;
        private String keyWhere;
        private String timeControl;
        private boolean paramField=false;
        private String orderField="";
        private String orderType;

        public boolean isXls() {
            return xls;
        }

        public void setXls(boolean xls) {
            this.xls = xls;
        }

        public boolean isBmath() {
            return bmath;
        }

        public void setBmath(boolean bmath) {
            this.bmath = bmath;
        }

        public boolean isAlldata() {
            return alldata;
        }

        public void setAlldata(boolean alldata) {
            this.alldata = alldata;
        }

        public boolean isOthercon() {
            return othercon;
        }

        public void setOthercon(boolean othercon) {
            this.othercon = othercon;
        }

        public String getPostId() {
            return postId;
        }

        public void setPostId(String postId) {
            this.postId = postId;
        }

        public String getXmlSql() {
            return xmlSql;
        }

        public void setXmlSql(String xmlSql) {
            this.xmlSql = xmlSql;
        }

        public String getSql() {
            return sql;
        }

        public void setSql(String sql) {
            this.sql = sql;
        }

        public String getSqlType() {
            return sqlType;
        }

        public void setSqlType(String sqlType) {
            this.sqlType = sqlType;
        }

        public String getDbType() {
            return dbType;
        }

        public void setDbType(String dbType) {
            this.dbType = dbType;
        }

        public String getPageType() {
            return pageType;
        }

        public void setPageType(String pageType) {
            this.pageType = pageType;
        }

        public String getNodeName() {
            return nodeName;
        }

        public void setNodeName(String nodeName) {
            this.nodeName = nodeName;
        }

        public String getNodeid() {
            return nodeid;
        }

        public void setNodeid(String nodeid) {
            this.nodeid = nodeid;
        }

        public String getTimeField() {
            return timeField;
        }

        public void setTimeField(String timeField) {
            this.timeField = timeField;
        }

        public String getKeyWhere() {
            return keyWhere;
        }

        public void setKeyWhere(String keyWhere) {
            this.keyWhere = keyWhere;
        }

        public String getTimeControl() {
            return timeControl;
        }

        public void setTimeControl(String timeControl) {
            this.timeControl = timeControl;
        }

        public boolean isParamField() {
            return paramField;
        }

        public void setParamField(String paramField) {
            if(paramField==null) this.paramField = false;
            else this.paramField=true;
        }

        public String getOrderField() {
            return orderField;
        }

        public void setOrderField(String orderField) {
            this.orderField = orderField;
        }

        public String getOrderType() {
            return orderType;
        }

        public void setOrderType(String orderType) {
            this.orderType = orderType;
        }

        public boolean isPrintSql() {
            return printSql;
        }

        public boolean isNoSum() {
            return noSum;
        }

        public String getOrderSql() {
            return orderSql;
        }

        public void setOrderSql(String orderSql) {
            this.orderSql = orderSql;
        }
    }

    private SysParam sysParam=new SysParam();
    private JSONObject param;
    private JSONObject single;       //单值
    private JSONObject condition;   //多个带条件
    private JSONObject all;          //多值
    private SqlRule sqlrule;
    private JSONObject otherControl;
    private boolean jpa;

    //table表名查询方式
    private QueryField.Page page=new QueryField.Page();
    private QueryRule rule=new QueryRule();
    private Format format;

    //数据包
    private JSONObject sum;
    private JSONObject allsum;
    private FromList fromtab;
    private JSONArray othersql;
    private QueryhTw htw;
    private GridHead head=new GridHead();
    private QryConfig qryConfig;

    private String execSql;
    private OSqlCallback oSqlCallback;

    public ConditionMap(Map param){
        if(param==null) this.param=new JSONObject();
        else this.param=new JSONObject(param);
    }

    public ConditionMap(JSONObject input) throws Exception {
        getBaseData(input);
    }

    public void getData(JSONObject input) throws Exception {
        param=input;
        condition=new JSONObject();
        single=new JSONObject();
        all=new JSONObject();
        if(param==null) return;
        getBaseData(param);
        getConditionData(param);
    }

    public void addData(JSONObject input) throws Exception {
        getBaseData(input);
        getConditionData(input);
    }

    public void getOtherSql() throws Exception {
        if(param==null) return;
        Object other=param.get("othersql");
        if(other==null) return;
        othersql= (JSONArray) other;
        int len=othersql.size();
        for(int i=0; i<len; i++){
            JSONObject m= othersql.get(i);
            FieldSql s= (FieldSql) m.get("sql");
            String alais=getFieldAlias(s.getField());
            if(alais!=null){
                s.setAlais(alais);
                rule.setExpField(m.getString("exp"), s, getFieldTable(s));
            }
        }
    }

    private Table getFieldTable(FieldSql s) throws Exception {
        if(fromtab==null) return null;
        return fromtab.getDictTable(fromtab.getTableFromAlias(s.getAlais()));
    }

    private String getFieldAlias(String field) throws Exception {
        if(fromtab==null) return null;
        int len=fromtab.size();
        for(int i=0; i<len; i++){
            Table tab=fromtab.getDictTable(fromtab.getTable(i));
            String scol=","+tab.getColumn()+",";
            if(scol.indexOf(","+field+",")>=0) return fromtab.getAlias(i);
        }
        return null;
    }

    public String getFieldTable(String field) throws Exception {
        if(fromtab==null) return null;
        int len=fromtab.size();
        for(int i=0; i<len; i++){
            Table tab=fromtab.getDictTable(fromtab.getTable(i));
            String scol=","+tab.getColumn()+",";
            if(scol.indexOf(","+field+",")>=0) return fromtab.getTable(i);
        }
        return null;
    }

    private void getConditionData(JSONObject input) throws Exception {
        if(jpa){
            ArrayList<String> klist=single.getKeylist();
            int klen=klist.size();
            for(int i=0; i<klen; i++){
                String key=klist.get(i);
                String key1=getJPANameTo(key);
                if(!key1.equals(key)){
                    single.put(key1, single.get(key));
                    all.put(key1, all.get(key));
                    single.remove(key);
                    all.remove(key);
                }
            }
        }
        Object con=input.get("condition");
        if(con==null) return;
        JSONArray conditionList = JSON.toJSONArray(con);
        int len=conditionList.size();
        for(int i=0; i<len; i++){
            JSONObject m=conditionList.getJSONObject(i);
            String field=m.getString("field");
            if(jpa){
                field=getJPANameTo(field);
            }
            FieldCondition f=new FieldCondition(field, m);
            Object value=condition.get(field);
            if(value!=null){
                ArrayList<FieldCondition> vlist=null;
                if(value instanceof FieldCondition){
                    vlist=new ArrayList<FieldCondition>();
                    vlist.add((FieldCondition) value);
                } else {
                    vlist= (ArrayList<FieldCondition>) value;
                }
                vlist.add(f);
                condition.put(field, vlist);
            } else {
                condition.put(field, f);
            }
            addSingle(field, f);
            addAll(field, f);
        }
    }

    private void getBaseData(JSONObject input) throws Exception {
        ArrayList<String> klist=input.getKeylist();
        int len=klist.size();
        for(int i=0; i<len; i++){
            String key=klist.get(i);
            String value=null;
            if(!"OSqlCallback".equals(key)){
                value=input.getString(key);
            }
            switch (key){
                case "nb_xmlsql":{
                    sysParam.setXmlSql(value);
                    input.remove(key);
                    break;
                }
                case "nb_sql":{
                    sysParam.setSql(value);
                    input.remove(key);
                    break;
                }
                case "nb_order":{
                    sysParam.setOrderSql(value);
                    input.remove(key);
                    break;
                }
                case "queryid":{
                    sysParam.setNodeName("select");
                    sysParam.setNodeid(value);
                    input.remove(key);
                    break;
                }
                case "tablesid":{
                    sysParam.setNodeName("tables");
                    sysParam.setNodeid(value);
                    input.remove(key);
                    break;
                }
                case "tableid":{
                    sysParam.setNodeName("table");
                    sysParam.setNodeid(value);
                    input.remove(key);
                    break;
                }
                case "OSqlCallback":{
                    oSqlCallback= (OSqlCallback) input.get(key);
                    input.remove(key);
                    break;
                }
                case "nb_table":{
                    if(sqlrule==null) sqlrule=new SqlRule();
                    String tabname=input.getString(key).toUpperCase();
                    JSONObject m=new JSONObject();
                    m.put("notIn", "0".equals(input.getString("table_in")));
                    m.put("fields", input.getString("table_filter"));
                    m.put("foreignKey", true);
                    m.put("wherefield", input.getString("table_key"));
                    sqlrule.addTable(tabname, m);
                    rule.setFrom(tabname);
                    sysParam.setTimeField(input.getString("table_time_field"));
                    sysParam.setKeyWhere(input.getString("table_key_where"));
                    sysParam.setTimeControl(input.getString("table_time_control"));
                    sysParam.setParamField(input.getString("table_param_field"));
                    input.remove(key);
                    input.remove("table_filter");
                    input.remove("table_in");
                    input.remove("table_key");
                    input.remove("table_time_field");
                    input.remove("table_key_where");
                    input.remove("table_time_control");
                    input.remove("table_param_field");
                    break;
                }
                case "nb_xls":{
                    sysParam.setXls(true);
                    input.remove(key);
                    break;
                }
                case "nb_alldata":{
                    sysParam.setAlldata(true);
                    input.remove(key);
                    break;
                }
                case "postId":{
                    sysParam.setPostId(value);
                    input.remove(key);
                    break;
                }
                case "nb_from":{
                    rule.setFrom(value);
                    input.remove(key);
                    break;
                }
                case "pageType":{
                    sysParam.setPageType(value);
                    input.remove(key);
                    break;
                }
                case "sqltype":{
                    sysParam.setSqlType(value);
                    input.remove(key);
                    break;
                }
                case "_orderField":{
                    sysParam.setOrderField(value);
                    input.remove(key);
                    break;
                }
                case "_orderType":{
                    sysParam.setOrderType(value);
                    input.remove(key);
                    break;
                }
                case "autoCompletion":{
                    if(value==null) break;
                    rule.setAutoCompletion(value);
                    input.remove(key);
                    break;
                }
                case "page":{
                    page.setPage(input.getIntValue(key));
                    input.remove(key);
                    break;
                }
                case "size":{
                    page.setSize(input.getIntValue(key));
                    input.remove(key);
                    break;
                }
                case "total":{
                    page.setTotal(input.getLongValue(key));
                    input.remove(key);
                    break;
                }
                case "gridheader":{
                    head.addHead(JSON.toJSONArray(input.get(key)));
                    input.remove(key);
                    break;
                }
                case "printSql":{
                    sysParam.printSql="true".equals(input.getString("printSql"));
                    input.remove(key);
                    break;
                }
                case "noSum":{
                    sysParam.noSum="true".equals(input.getString("noSum"));
                    input.remove(key);
                    break;
                }
                case "jpa":{
                    jpa="true".equals(input.getString("jpa"));
                    input.remove(key);
                    break;
                }
                default:{
                    Object v=input.get(key);
                    addAll(key, v);
                    if(single==null) single=new JSONObject();
                    single.put(key, v);
                    break;
                }
            }
        }

        if((page.getPage()>0 && page.getSize()<=0)||(page.getPage()<=0 && page.getSize()>0)){
            throw new Exception("分页查询要求page和size入参值必须大于0");
        }
        if(page.getPage()>0 && page.getSize()>0) {
            page.setStartPage((page.getPage()-1)*page.getSize()+1);
            page.setEndPage(page.getPage()*page.getSize());
        }

        if(sqlrule!=null){
            if(sysParam.getSqlType()==null){
                throw new Exception("表执行方式对应sqltype值必填！");
            }
            sqlrule.getCacheKey(sysParam.getSqlType());
        }

        if(sysParam.getXmlSql()!=null && sysParam.getSql()!=null){
            throw new Exception("nb_xmlsql和nb_sql不允许两个都填，请检查代码逻辑！");
        }

        if(sysParam.getXmlSql()!=null || sysParam.getSql()!=null){
            String s;
            if(sysParam.getXmlSql()!=null) s=sysParam.getXmlSql();
            else s=sysParam.getSql();
            String s1=s.toLowerCase();
            if(s1.indexOf("<if")>=0 || s1.indexOf("<foreach")>=0){
                sysParam.setSql(null);
                sysParam.setXmlSql(s);
            } else {
                sysParam.setSql(s);
                sysParam.setXmlSql(null);
            }
        }
    }

    public void addSingle(String field, FieldCondition f) throws Exception {
        if(field.equals("condition")) return;
        if("EQ".equals(f.getOperator()) || "IN".equals(f.getOperator())){
            if(single.get(field)!=null){
                throw new Exception("请检查查询条件入参KEY值数据，等于类型的变量["+field+"]只允许设定一个");
            }
            single.put(field, f.getValue());
        }
    }

    private void addAll(String key, Object f){
        if(all==null) return;
        Object value=all.get(key);
        ArrayList<FieldCondition> list=null;
        if(value==null){
            list=new ArrayList<FieldCondition>();
        } else {
            list= (ArrayList<FieldCondition>) value;
        }
        if(f instanceof FieldCondition) list.add((FieldCondition) f);
        else {
            if(f instanceof Array){
                list.add(new FieldCondition(key, "IN", f, null));
            } else {
                list.add(new FieldCondition(key, "EQ", f, null));
            }

        }
        all.put(key, list);
    }

    public Object getFieldValue(String key) throws Exception {
        if(single==null) return null;
        return single.get(key);
    }

    public ArrayList<FieldCondition> getField(String key) throws Exception {
        Object value=all.get(key);
        if(value==null) return null;
        return (ArrayList<FieldCondition>) value;
    }

    public FieldCondition getField(String key, int i) throws Exception {
        Object value=single.get(key);
        if(value==null){
            value=condition.get(key);
            if(value!=null){
                FieldCondition field=null;
                if(value instanceof Map){
                    field= (FieldCondition) JSON.toBean(value, FieldCondition.class);
                } else {
                    JSONArray list= (JSONArray) value;
                    int len=list.size();
                    if(i+1>len){
                        throw new Exception("条件["+key+"]变量索引有误，请检查代码逻辑！");
                    }
                    return (FieldCondition) JSON.toBean(list.get(i), FieldCondition.class);
                }
            }
        } else return  new FieldCondition(key, "EQ", value, null);
        return null;
    }

    public void updateKey(String key, String nkey){
        Object value=single.get(key);
        if(value!=null){
            single.remove(key);
            single.put(nkey, value);
        }
        value=condition.get(key);
        if(value!=null){
            condition.remove(key);
            condition.put(nkey, value);
        }
        value=all.get(key);
        if(value!=null){
            all.remove(key);
            all.put(nkey, value);
        }
    }

    public void setRole(JSONArray list) throws Exception {
        String cx=null;
        if(single==null) return;
        String sysId=single.getString("sysId");
        JSONObject m=SysSql.getRole(sysId, list, sysParam.getPostId(), single);
        if(m==null) return;
        param.put("othersql",m.getJSONArray("auth"));
        ArrayList<String> klist=m.getKeylist();
        int len=klist.size();
        for(int i=0; i<len; i++){
            String key=klist.get(i);
            if(!"auth".equals(key)){
                if(single.get(key)==null){
                    addAll(key, SqlNodeVar.getInnerValue());
                    single.put(key, SqlNodeVar.getInnerValue());
                }

            }
        }
    }

    public int getPage() {
        return page.getPage();
    }

    public int getSize() {
        return page.getSize();
    }

    public int getStartPage() {
        return page.getStartPage();
    }

    public int getEndPage() {
        return page.getEndPage();
    }

    public long getTotal() {
        return page.getTotal();
    }

    public String getPostId() {
        return sysParam.getPostId();
    }

    public String getQueryId() {
        if("select".equals(sysParam.getNodeName())) return sysParam.getNodeid();
        return null;
    }

    public String gettablesId() {
        if("tables".equals(sysParam.getNodeName())) return sysParam.getNodeid();
        return null;
    }

    public String gettableId() {
        if("table".equals(sysParam.getNodeName())) return sysParam.getNodeid();
        return null;
    }

    public String getXmlSql() {
        return sysParam.getXmlSql();
    }

    public String getSql() {
        return sysParam.getSql();
    }

    public String getTable() {
        if(sqlrule==null) return null;
        return sqlrule.getTable();
    }

    public String getSqlType() {
        return sysParam.getSqlType();
    }

    public int getTotalPage() {
        return page.getTotalpage();
    }

    public void setTotal(long total) {
        page.setTotal(total);
        if(page.getSize()>0){
            double dtotle = (double) page.getTotal() / (double) page.getSize();
            dtotle = Math.ceil(dtotle);
            page.setTotalpage((int)dtotle);
        }
    }

    public String getFrom() {
        return rule.getFrom();
    }

    public boolean isAutoCompletion() {
        if(rule.getAutoCompletion()==null) return true;
        return "1".equals(rule.getAutoCompletion());
    }

    public JSONObject getSingle() {
        return single;
    }

    public JSONObject getCondition() {
        return condition;
    }

    public ArrayList<String> getKeylist(){
        return all.getKeylist();
    }

    public void setAutoCompletion(String autoCompletion) {
        rule.setAutoCompletion(autoCompletion);
    }

    public void setSqlType(String sqlType) {
        sysParam.setSqlType(sqlType);
    }

    public Format getFormat() {
        return format;
    }

    public QueryRule getRule() {
        return rule;
    }

    public void setRule(QueryRule rule) throws Exception {
        if(rule==null) return;
        this.rule = rule;
        if(rule==null) format=null;
        else format=new Format(rule);
        if(!"order".equals(this.rule.getPage())) sysParam.setBmath(false);
        else sysParam.setBmath(true);
    }

    public String getExpain(){
        if(rule==null) return null;
        return rule.getExpain();
    }

    public String getPageSet(){
        if(rule==null) return null;
        return rule.getPage();
    }

    public JSONObject getSum() {
        return sum;
    }

    public JSONObject getAllsum() {
        return allsum;
    }

    public void setSum(JSONObject sum) {
        this.sum = sum;
    }

    public void setAllsum(JSONObject allsum) {
        this.allsum = allsum;
    }

    public FromList getFromtab() {
        return fromtab;
    }

    public void setFromtab(FromList fromtab) throws Exception {
        this.fromtab = fromtab;
        if(qryConfig==null) return;
        if(this.fromtab!=null && !sysParam.isOthercon()){
            ArrayList<String> klist=all.getKeylist();
            int len=klist.size();
            for(int i=0; i<len; i++){
                String key=klist.get(i);
                String k=key;
                if(qryConfig.getQryConType()!=null && qryConfig.getSqlCallback()!=null){
                    k=qryConfig.getSqlCallback().getField(this.fromtab, key);
                }
                if(k==null) k=key;
                if(!key.equals(k)) updateKey(key,k);
            }
            sysParam.setOthercon(true);
        }
    }

    public JSONArray getSumArray() throws Exception {
        JSONArray list=new JSONArray();
        if(sum!=null){
            list.add(sum);
        }
        if(allsum!=null){
            list.add(allsum);
        }
        if(list.size()>0) return list;
        return null;
    }

    public String getDbType() {
        return sysParam.getDbType();
    }

    public void setDbType(String dbType) {
        sysParam.setDbType(dbType);
    }

    public boolean isXls() {
        return sysParam.isXls();
    }

    public boolean isAlldata() {
        return sysParam.isAlldata();
    }

    public boolean isBmath() {
        return sysParam.isBmath();
    }

    public QueryhTw getHtw() {
        return htw;
    }

    public void setHtw(QueryhTw htw) throws Exception {
        this.htw = htw;
    }

    public JSONArray getHead(){
        if(htw==null) return head.getHead();
        else return htw.getHead();
    }

    public void setHead(GridHead head) throws Exception {
        if(head==null) return;
        this.head=head;
    }

    public QryConfig getQryConfig() {
        return qryConfig;
    }

    public void setQryConfig(QryConfig qryConfig) {
        this.qryConfig = qryConfig;
    }

    public SqlCallback getSqlCallback() {
        if(qryConfig==null) return null;
        return qryConfig.getSqlCallback();
    }

    public String getOutputWeb() {
        if(qryConfig==null) return null;
        return qryConfig.getOutputWeb();
    }

    public String getSysId() {
        if(qryConfig==null) return null;
        return qryConfig.getSysId();
    }

    public String getQryConType() {
        if(qryConfig==null) return null;
        return qryConfig.getQryConType();
    }

    public String getOutputType() {
        if(qryConfig==null) return null;
        return qryConfig.getOutputType();
    }

    public SqlRule getSqlrule() {
        return sqlrule;
    }

    public void setSqlrule(SqlRule sqlrule) throws Exception {
        this.sqlrule = sqlrule;
        if(this.sqlrule!=null){
            ArrayList<SqlRule.Table> list=this.sqlrule.getTables();
            int len=list.size();
            for(int i=0; i<len; i++){
                if(list.get(i).getParam()!=null){
                    addData(list.get(i).getParam());
                }
            }
        }
    }

    public String getSqlruleFields(String tabName) throws Exception {
        if(sqlrule==null) return null;
        if(sqlrule.getTable(tabName)==null) return null;
        return sqlrule.getTable(tabName).getFields();
    }

    public boolean getSqlruleNotIn(String tabName) throws Exception {
        if(sqlrule==null) return false;
        if(sqlrule.getTable(tabName)==null) return false;
        return sqlrule.getTable(tabName).isNotIn();
    }

    public boolean getSqlruleForeignKey(String tabName) throws Exception {
        if(sqlrule==null) return true;
        if(sqlrule.getTable(tabName)==null) return true;
        return sqlrule.getTable(tabName).isForeignKey();
    }

    public SqlRule.Table getSqlruleTable(String tabName) throws Exception {
        if(sqlrule==null) return null;
        if(sqlrule.getTable(tabName)==null) return null;
        return sqlrule.getTable(tabName);
    }

    public String getCacheKey() {
        if(sqlrule==null) return null;
        return sqlrule.getCacheKey(sysParam.getSqlType());
    }

    public String getExecSql() {
        return execSql;
    }

    public void setExecSql(String execSql) {
        this.execSql = execSql;
    }

    public String getNodeName() {
        return sysParam.getNodeName();
    }

    public String getNodeid() {
        return sysParam.getNodeid();
    }

    public String getTimeField() {
        return sysParam.getTimeField();
    }

    public boolean isKeyWhere() {
        return "1".equals(sysParam.getKeyWhere());
    }

    public boolean isTimeControl() {
        return "1".equals(sysParam.getTimeControl());
    }

    public boolean isParamField() {
        return sysParam.isParamField();
    }

    public String getOrderField() {
        return sysParam.getOrderField();
    }

    public String getOrderType() {
        return sysParam.getOrderType();
    }

    public boolean isPrintSql() {
        return sysParam.isPrintSql();
    }

    public boolean isNoSum() {
        return sysParam.isNoSum();
    }

    public JSONObject getOtherControl() {
        return otherControl;
    }

    public void setOtherControl(JSONObject otherControl) {
        this.otherControl = otherControl;
    }

    public void setXmlSql(String xmlsql){
        this.sysParam.setXmlSql(xmlsql);
    }

    public void setPageType(String pageType){
        this.sysParam.setPageType(pageType);
    }

    public String getPageType(){
        return this.sysParam.getPageType();
    }

    public String getOrderSql(){
        return sysParam.getOrderSql();
    }

    public FieldValueCallback getFieldValueCallback() {
        if(qryConfig!=null) return qryConfig.getFieldValueCallback();
        return null;
    }

    public OSqlCallback getoSqlCallback() {
        return oSqlCallback;
    }

    public boolean isJpa() {
        return jpa;
    }
}
